home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / zsource / main.c < prev    next >
C/C++ Source or Header  |  1988-05-18  |  13KB  |  700 lines

  1. /*
  2.  *     Main Module
  3.  *
  4.  *        Jwahar Bammi
  5.  *            usenet: mandrill!bammi@{decvax,sun}.UUCP
  6.  *            csnet:  bammi@mandrill.ces.CWRU.edu
  7.  *            arpa:   bammi@mandrill.ces.CWRU.edu
  8.  *            CompuServe: 71515,155
  9.  */
  10.  
  11. #include "config.h"
  12.  
  13. #include "zmdm.h"
  14. #include "common.h"
  15.  
  16. #ifndef Vsync             /* Atari forgot these in osbind.h */
  17. #define Vsync()    xbios(37)
  18. #endif
  19.  
  20. #define    esc    27
  21. #define cr    0x0d
  22. #define mvto(r,c)    EscSeq('Y');Bconout(2,r+040);Bconout(2,c+040)
  23.  
  24.  
  25.      /* Globals belonging to this module only */
  26.  
  27. int    rs232 = 1,        /* Ports */
  28.         console = 2;
  29. int    speed,              /* rs232 setup parameters */
  30. #ifdef FLOW_CTRL
  31.      flowctl = 1,
  32. #else
  33.     flowctl = 0,
  34. #endif
  35.     ucr = -1,
  36.     rsr = -1,
  37.     tsr = -1,
  38.     scr = -1;
  39.  
  40. /*
  41.  * setRs232() - set rs232 port configuration
  42.  */
  43. #ifndef REMOTE
  44. void setRs232 ()
  45. {
  46.     char ch;
  47.     long conin;
  48.     
  49.     Bconws("Baud rate: ");
  50.     EscSeq('p');
  51.     Bconws("0=19200 1=9600, 2=4800, 3=2400, 4=1200, 5=300\r\n");
  52.     EscSeq('q');
  53.     Bconout(2, '\t');
  54.     EscSeq('p');
  55.     Bconws("What speed==>");
  56.     EscSeq('q');
  57.     
  58.     conin = Bconin(console);    /* get speed */
  59.     if ((conin & 0x00FF0000L) == 0x00610000L)
  60.     {
  61.         his_screen();
  62.         ResetIoBuf();
  63.         finish();
  64.     }
  65.     ch = (char) (conin & 0x007f);
  66.     Bconout(2, ' ');
  67.     switch (ch)
  68.     {
  69.         case '0':        /* 19200 */
  70.         speed = 0;
  71.         Bconws("19200");
  72.         Baudrate = 19200;
  73.         break;
  74.         
  75.         case '1':
  76.         speed = 1;    /* 9600 */
  77.         Bconws("9600");
  78.         Baudrate = 9600;
  79.         break;
  80.         
  81.         case '2':
  82.         speed = 2;    /* 4800 */
  83.         Bconws("4800");
  84.         Baudrate = 4800;
  85.         break;
  86.         
  87.         case '3':
  88.         speed = 4;    /* 2400 */
  89.         Bconws("2400");
  90.         Baudrate = 2400;
  91.         break;
  92.         
  93.         case '4':
  94.         speed = 7;    /* 1200 */
  95.         Bconws("1200");
  96.         Baudrate = 1200;
  97.         break;
  98.         
  99.         case '5':
  100.         speed = 9;    /* 300 */
  101.         Bconws("300");
  102.         Baudrate = 300;
  103.         break;
  104.         
  105.         default:
  106.         speed = getbaud();
  107.         Bconws(BAUD_STRING(speed));
  108.         Baudrate = BAUD_RATE(speed);
  109.     }
  110.     Bconws(" Baud\r\n");
  111.     
  112.     /* Set new Baud rate */
  113.  
  114. /*    Txoff(); */
  115.     Rsconf(speed, flowctl, ucr, rsr, tsr, scr);
  116.     Vsync(); Vsync();
  117. /*    Txon(); */
  118.  
  119.     
  120. }
  121. #else
  122. void setRs232 ()
  123. {
  124.     char ch;
  125.     long conin;
  126.     
  127.     Bauxws("Baud rate: ");
  128.     Bauxws("0=19200 1=9600, 2=4800, 3=2400, 4=1200, 5=300\r\n");
  129.     Bconout(1, '\t');
  130.     Bauxws("What speed==>");
  131.     
  132.     conin = Bconin(1);    /* get speed */
  133.     if (((int)(conin & 0x007f) & CTRL('U')) == CTRL('U'))
  134.     {
  135.         his_screen();
  136.         ResetIoBuf();
  137.         finish();
  138.     }
  139.     ch = (char) (conin & 0x007f);
  140.     Bconout(1, ' ');
  141.     switch (ch)
  142.     {
  143.         case '0':        /* 19200 */
  144.         speed = 0;
  145.         Bauxws("19200");
  146.         Baudrate = 19200;
  147.         break;
  148.         
  149.         case '1':
  150.         speed = 1;    /* 9600 */
  151.         Bauxws("9600");
  152.         Baudrate = 9600;
  153.         break;
  154.         
  155.         case '2':
  156.         speed = 2;    /* 4800 */
  157.         Bauxws("4800");
  158.         Baudrate = 4800;
  159.         break;
  160.         
  161.         case '3':
  162.         speed = 4;    /* 2400 */
  163.         Bauxws("2400");
  164.         Baudrate = 2400;
  165.         break;
  166.         
  167.         case '4':
  168.         speed = 7;    /* 1200 */
  169.         Bauxws("1200");
  170.         Baudrate = 1200;
  171.         break;
  172.         
  173.         case '5':
  174.         speed = 9;    /* 300 */
  175.         Bauxws("300");
  176.         Baudrate = 300;
  177.         break;
  178.         
  179.         default:
  180.         speed = getbaud();
  181.         Bauxws(BAUD_STRING(speed));
  182.         Baudrate = BAUD_RATE(speed);
  183.     }
  184.     Bauxws(" Baud\r\n");
  185.     
  186.     /* Set new Baud rate */
  187.  
  188. /*    Txoff(); */
  189.     Rsconf(speed, flowctl, ucr, rsr, tsr, scr);
  190.     Vsync(); Vsync();
  191. /*    Txon(); */
  192.  
  193.     
  194. }
  195. #endif /* REMOTE */
  196.  
  197. /*
  198.  * help() - display help info and menu
  199.  */
  200. #ifndef REMOTE
  201. void help ()
  202. {
  203.     register long conin;
  204.     register int x;
  205.     extern char *r_filename();
  206.     
  207.     my_screen();        /* Switch to my screen memory */
  208.     EscSeq('v');        /* wrap at end of line */
  209.     EscSeq('E');        /* clear screen */
  210.     
  211.     mvto(2,25);
  212.     EscSeq('p');
  213.     Bconws("ZMDM Version ");
  214.     Bconws(ZMDMVERSION);
  215.     EscSeq('q');
  216.     EscSeq('p');
  217.     x = strlen(COMPILER);
  218.     x = (80 - x)/2;
  219.     mvto(3,x);
  220.     Bconws(COMPILER);
  221.     EscSeq('q');
  222.     mvto(5,25);
  223.     Bconws("ST Enthusiasts @ ces.CWRU.edu\r\n\n");
  224.  
  225.     /* Put up menu */
  226.     Bconws("\r\n\t");
  227.     EscSeq('p');        /* reverse video */
  228.     Bconws("Undo");
  229.     EscSeq('q');        /* quit reverse video */
  230.     Bconws(" to exit.\r\n");
  231.     
  232.     Bconws("\t");
  233.     EscSeq('p');        /* reverse video */
  234.     Bconws("Help");
  235.     EscSeq('q');        /* quit reverse video */
  236.     Bconws(" for this message.\r\n");
  237.  
  238.     Bconws("\t");
  239.     EscSeq('p');        /* reverse video */
  240.     Bconws("Escape");
  241.     EscSeq('q');        /* quit reverse video */
  242.     Bconws(" to send a break.\r\n");
  243.     
  244.     Bconws("\t");
  245.     EscSeq('p');        /* reverse video */
  246.     Bconws("T or t");
  247.     EscSeq('q');        /* quit reverse video */
  248.     Bconws(" to do file transfers and local functions.\r\n");
  249.  
  250. #ifdef PHONES
  251.     Bconws("\t");
  252.     EscSeq('p');        /* reverse video */
  253.     Bconws("P or p");
  254.     EscSeq('q');        /* quit reverse video */
  255.     Bconws(" for Phone services.\r\n");
  256. #endif
  257.  
  258.     if(rez == 2)
  259.     {
  260.         Bconws("\t");
  261.         EscSeq('p');        /* reverse video */
  262.         Bconws("H or h");
  263.         EscSeq('q');        /* quit reverse video */
  264.         Bconws(" for Hi Rez Toggle (25/50 Lines).\r\n");
  265.     }
  266.  
  267.     Bconws("\t");
  268.     EscSeq('p');        /* reverse video */
  269.     Bconws("I or i");
  270.     EscSeq('q');        /* quit reverse video */
  271.     Bconws(" to Invert screen colors.\r\n");
  272.     
  273.     Bconws("\t");
  274.     EscSeq('p');        /* reverse video */
  275.     Bconws("Return");
  276.     EscSeq('q');        /* quit reverse video */
  277.     Bconws(" to do nothing.\r\n");
  278.     
  279.     Bconws("\t");
  280.     EscSeq('p');        /* reverse video */
  281.     Bconws("B or b");
  282.     EscSeq('q');        /* quit reverse video */
  283.     Bconws(" to set baud rate.     Currently is ");
  284.     EscSeq('p');
  285.     Bconws(BAUD_STRING(speed));
  286.     Bconws(" Baud.\r\n\r\n");
  287.     EscSeq('q');
  288.  
  289.     /* get response */
  290.     conin = Bconin(console);
  291.  
  292.     if ((conin & 0x00FF0000L) == 0x00610000L)
  293.     {
  294.         /* He hit <UNDO> */
  295.         his_screen();
  296.         ResetIoBuf();
  297.         finish();
  298.     }
  299.     
  300.     switch((int)(conin & 0x007f))
  301.     {
  302.         case 'B':
  303.         case 'b':
  304.         /* Set baud rate */
  305.         setRs232();
  306.         break;
  307.         
  308.         case 'T':
  309.         case 't':
  310.             EscSeq('E');        /* clear screen */
  311.  
  312.             /* Set no flow Control */
  313. #ifdef FLOW_CTRL
  314.             Rsconf(-1,0,-1,-1,-1,-1);
  315.             Vsync(); Vsync();
  316.  
  317. #endif
  318.         /* Go do transfers */
  319.         transfer();
  320.             
  321. #ifdef FLOW_CTRL
  322.             /* Flow Control On */
  323. /*            Txoff(); */
  324.             Rsconf(-1,1,-1,-1,-1,-1);
  325.             Vsync(); Vsync();
  326. /*            Txon(); */
  327. #endif
  328.         his_screen();
  329.         return;
  330.         
  331.         case '\033':
  332.         /* Send a break */
  333.         sendbrk();
  334.         his_screen();    /* Don't wait for the key hit */
  335.  
  336.         return;
  337.  
  338.         case 'i':
  339.         case 'I':
  340.         /* Invert screen colors */
  341.         his_screen();
  342.         if(scolor == 0)
  343.         {
  344.             EscSeq('b');    /* Foreground color 0 */
  345.             Bconout(2, 0);
  346.             EscSeq('c');    /* Background color 1 */
  347.             Bconout(2, 1);
  348.             scolor = 1;
  349.         }
  350.         else
  351.         {
  352.             EscSeq('b');    /* Foreground color 1 */
  353.             Bconout(2, 1);
  354.             EscSeq('c');    /* Background color 0 */
  355.             Bconout(2, 0);
  356.             scolor = 0;
  357.         }
  358.         EscSeq('E');        /* Clear the screen */
  359.         return;
  360.  
  361. #ifdef PHONES
  362.         case 'p':
  363.         case 'P':
  364.         /* Phone Services */
  365.         phone();
  366.         return;
  367. #endif
  368.         case 'h':
  369.         case 'H':
  370.         /* Hi rez 25/50 toggle */
  371.         if(rez == 2)
  372.         {
  373.             if(hlines == 25)
  374.             {
  375.                 hlines = 50;
  376.                 hi50();
  377.             }
  378.             else
  379.             {
  380.                 hlines = 25;
  381.                 hi25();
  382.             }
  383.             his_screen();
  384.             EscSeq('E');        /* clear screen */
  385.             return;
  386.         }
  387.         /* else fall Through */
  388.         
  389.         default:
  390.         Bconws("No Change\r\n");
  391.     }
  392.  
  393.     /* Wait for a key hit */
  394.     hit_key();
  395.     /* back to terminal screen */
  396.     his_screen();
  397. }
  398. #else
  399. void help ()
  400. {
  401.     register long conin;
  402.     extern char *r_filename();
  403.     
  404.     my_screen();        /* Switch to my screen memory */
  405.     
  406.     Bauxws("\r\n\n");
  407.     Bauxws("                        RZMDM Version ");
  408.     Bauxws(ZMDMVERSION);
  409.     Bauxws("\r\n                         ");
  410.     Bauxws(COMPILER);
  411.     Bauxws("\r\n\n                        ST Enthusiasts @ ces.CWRU.edu\r\n\n");
  412.  
  413.     /* Put up menu */
  414.     Bauxws("\r\n\t");
  415.     Bauxws("CTRL-U");
  416.     Bauxws(" to exit.\r\n");
  417.     
  418.     Bauxws("\t");
  419.     Bauxws("CTRL-Z");
  420.     Bauxws(" for this message.\r\n");
  421.  
  422.     Bauxws("\t");
  423.     Bauxws("Escape");
  424.     Bauxws(" to send a break.\r\n");
  425.     
  426.     Bauxws("\t");
  427.     Bauxws("T or t");
  428.     Bauxws(" to do file transfers and local functions.\r\n");
  429.  
  430.     Bauxws("\t");
  431.     Bauxws("Return");
  432.     Bauxws(" to do nothing.\r\n");
  433.     
  434.     Bauxws("\t");
  435.     Bauxws("B or b");
  436.     Bauxws(" to set baud rate.     Curently is ");
  437.     Bauxws(BAUD_STRING(speed));
  438.     Bauxws(" Baud.\r\n\r\n");
  439.  
  440.     /* get response */
  441.     conin = Bconin(1);
  442.  
  443.     if (((int)(conin & 0x007f) & CTRL('U')) == CTRL('U'))
  444.     {
  445.         /* He hit <UNDO> */
  446.         his_screen();
  447.         ResetIoBuf();
  448.         finish();
  449.     }
  450.     
  451.     switch((int)(conin & 0x007f))
  452.     {
  453.         case 'B':
  454.         case 'b':
  455.         /* Set baud rate */
  456.         setRs232();
  457.         break;
  458.         
  459.         case 'T':
  460.         case 't':
  461.             Bauxws("\r\n\n");        /* clear screen */
  462.  
  463.             /* Set no flow Control */
  464. #ifdef FLOW_CTRL
  465.             Rsconf(-1,0,-1,-1,-1,-1);
  466.             Vsync(); Vsync();
  467.  
  468. #endif
  469.         /* Go do transfers */
  470.         transfer();
  471.             
  472. #ifdef FLOW_CTRL
  473.             /* Flow Control On */
  474. /*            Txoff(); */
  475.             Rsconf(-1,1,-1,-1,-1,-1);
  476.             Vsync(); Vsync();
  477. /*            Txon(); */
  478. #endif
  479.         his_screen();
  480.         return;
  481.         
  482.         case '\033':
  483.         /* Send a break */
  484.         sendbrk();
  485.         his_screen();    /* Don't wait for the key hit */
  486.  
  487.         return;
  488.  
  489.         /* else fall Through */
  490.         
  491.         default:
  492.         Bauxws("No Change\r\n");
  493.     }
  494.  
  495.     /* back to terminal screen */
  496.     his_screen();
  497. }
  498. #endif /* REMOTE */
  499.  
  500. main ()
  501. {
  502.     register int    c;        /* rs232 input */
  503.     register int    i;
  504.     register long    conin;
  505. #ifndef REMOTE
  506.     extern int *aaddress(); /* Routine that returns base address of
  507.                  * line A variables
  508.                  */
  509. #else
  510.     extern FILE *fopen();
  511. #endif
  512.  
  513. #if (MWC || MANX)
  514.     extern char *lmalloc();
  515. #endif
  516.  
  517.     /* Set up Dta */
  518.     Fsetdta(&statbuf);
  519.  
  520.     /* Get screen rez */
  521.     rez = Getrez();
  522.     drv_map = Drvmap();
  523.  
  524. #if (MWC || MANX)
  525. #ifndef REMOTE
  526.        if((m_screen = (long *)lmalloc(
  527.                    (unsigned long)((8L*1024L+32L)*(long)sizeof(long))))
  528.                             == (long *)NULL)
  529.     {
  530.         Bconws("Sorry, could not allocate enough memory\r\n");
  531.         Pterm(3);
  532.     }
  533. #endif /* REMOTE */
  534. #ifndef DYNABUF
  535.     if((bufr = (unsigned char *)lmalloc((unsigned long)BBUFSIZ))
  536.                      == (unsigned char *)NULL)
  537. #else
  538.     if((bufr = dalloc()) == (unsigned char *)NULL)
  539. #endif /* DYNABUF */
  540.     {
  541. #ifdef REMOTE
  542.         Bauxws("Sorry, could not allocate enough memory\r\n");
  543. #else
  544.         Bconws("Sorry, could not allocate enough memory\r\n");
  545. #endif
  546.  
  547.         Pterm(4);
  548.     }
  549.  
  550. #else /* MWC || MANX */
  551. #ifdef DYNABUF
  552.     if((bufr = dalloc()) == (unsigned char *)NULL)
  553.     {
  554. #ifdef REMOTE
  555.         Bauxws("Sorry, could not allocate enough memory\r\n");
  556. #else
  557.         Bconws("Sorry, could not allocate enough memory\r\n");
  558. #endif
  559.         Pterm(5);
  560.     }
  561. #endif /* DYNABUF */
  562. #endif /* MWC || MANX */
  563.  
  564. #ifndef REMOTE
  565. #if (MWC || MANX)
  566.     ms_ptr = (long *) ((0xffffff00L & ((long)(m_screen))) + 0x00000100L);
  567. #else
  568.     ms_ptr = (long *) ((0xffffff00L & ((long)(&m_screen[0]))) + 0x00000100L);
  569. #endif /* MWC */
  570.  
  571.     EscSeq('e');        /* Turn on the cursor */
  572.     EscSeq('v');        /* wrap at end of line */
  573.     EscSeq('E');        /* clear screen */
  574. #endif /* REMOTE */
  575.  
  576.     SetIoBuf();
  577.  
  578.     speed = getbaud();
  579. /*    Txoff(); */
  580.     Rsconf((int) speed, flowctl, ucr, rsr, tsr, scr);  /* init set */
  581.     Vsync(); Vsync();
  582. /*    Txon();     */
  583.  
  584.     Baudrate = BAUD_RATE(speed);
  585.     
  586. #ifndef REMOTE
  587.     aline_addr = aaddress();
  588.     STDERR = stderr;
  589. #else
  590. #ifndef DLIBS
  591.     if((STDERR = fopen("aux:", "rw")) == (FILE *)NULL)
  592.     {
  593.         Bauxws("Could not Open Aux Stream for Stderr\r\n");
  594.         finish();
  595.     }
  596.     setbuf(STDERR, (char *)NULL);
  597. #else
  598.     STDERR = stdaux;
  599. #endif /* DLIBS */
  600.     
  601. #endif /* remote */
  602.  
  603.     help();
  604.  
  605.     i = 0;
  606.     while (0 == 0)    /* infinite loop */
  607.     {
  608. #ifndef REMOTE
  609.         while (Bconstat(rs232) != 0)
  610.         {
  611.             /* Char at Modem */
  612.             c = Bconin(rs232) & 0x007f;
  613.             Bconout(console, c);
  614.  
  615.             /* Check the console once in a while */
  616.             /* important at High speeds */
  617.             if ((++i) & 32)
  618.             {
  619.                 if (Bconstat(console) != 0)
  620.                       {
  621.                     conin = Bconin(console);
  622.                     Bconout(rs232, (int) (conin & 0x007f));
  623.                 }
  624.                 i = 0;
  625.             }
  626.                 
  627.         }
  628.         
  629.         if (Bconstat(console) != 0)
  630.         {
  631.             /* Char at Console */
  632.             conin = Bconin(console);
  633.             if ((conin & 0x00FF0000L) == 0x00610000L)  /* Undo */
  634.             {
  635.                 ResetIoBuf();
  636.                 finish();
  637.             }
  638.             
  639.             if ((conin & 0x00FF0000L) == 0x00620000L)  /* Help */
  640.                 help();
  641.             else
  642.                 Bconout(rs232, (int) (conin & 0x007f));
  643.         }
  644. #else
  645.         while (Bconstat(rs232) != 0)
  646.         {
  647.             /* Char at Modem */
  648.             c = Bconin(rs232) & 0x007f;
  649.  
  650.             if ((c & CTRL('U')) == CTRL('U'))  /* Undo */
  651.             {
  652.                 ResetIoBuf();
  653.                 finish();
  654.             }
  655.             
  656.             if ((c & CTRL('Z')) == CTRL('Z'))  /* Help */
  657.                 help();
  658.             else
  659.                 Bconout(rs232,c);
  660.         }
  661.  
  662. #endif /* REMOTE */
  663.     }
  664. }
  665.  
  666. finish()
  667. {
  668. #ifdef PHONES
  669.     /* Save phone directory if it changed */
  670.     extern int dchanged;
  671.  
  672.     if(dchanged)
  673.     {
  674.         if(writedir() == 1)
  675.             hit_key();
  676.     }
  677. #endif
  678.  
  679. #if (MWC || MANX)
  680. #ifdef DYNABUF
  681.     Mfree(bufr);
  682. #else
  683.     free(bufr);
  684. #endif
  685.  
  686. #ifndef REMOTE
  687.     free(m_screen);
  688. #endif
  689.  
  690. #else
  691.  
  692. #ifdef DYNABUF
  693.     Mfree(bufr);
  694. #endif
  695. #endif
  696.     exit(0);
  697. }
  698.  
  699. /* -eof- */
  700.